home *** CD-ROM | disk | FTP | other *** search
/ PD ROM 1 / PD ROM Volume I - Macintosh Software from BMUG (1988).iso / Stacks / Updates⁄New / TEXAS for BMUG / C progs / brwsr.2 ƒ / brwsr.2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-11-03  |  3.8 KB  |  141 lines  |  [TEXT/KAHL]

  1. /* program to let a user browse through an indexed document/database
  2.  * ... works with indices created by ndxr.c program ...
  3.  * by ^z - 870805-13-...
  4.  *
  5.  */
  6.  
  7.  
  8. /* main function does the work of interpreting the user's commands:
  9.  *
  10.  *    ?            print out helpful info
  11.  *    :            quit program
  12.  *    :fnord        open document file 'fnord' for browsing
  13.  *    >grok        append copy of future output to notes file 'grok'
  14.  *    >            end copying to notes file
  15.  *    'DON.MAC    append comment string 'DON.MAC' to notes file
  16.  *    xyzzy        jump to INDEX item 'XYZZY'
  17.  *    ".012345    take string '.012345' as target for jump
  18.  *    -17            back up 17 lines from here
  19.  *    -            back up one line; same as '-1' command
  20.  *    +23            jump down 23 lines from here
  21.  *    + or <ret>    move down one line; same as '+1' command
  22.  *    .29            print 29 lines from here
  23.  *    =            descend:  INDEX -> CONTEXT -> TEXT display
  24.  *    ^            ascend:  TEXT -> CONTEXT -> INDEX display
  25.  *    *            empty 'working subset' proximity filter (nothing valid)
  26.  *    **            fill 'working subset' (everything valid)
  27.  *    &            add word-neighborhood of current index item to subset
  28.  *    &&            add sentence-neighborhood to subset
  29.  *    &&&            add paragraph-neighborhood to subset
  30.  *  ~            invert (logical NOT) entire working subset
  31.  *    ;            repeat previous command
  32.  *    
  33.  */
  34.  
  35.  
  36. #include <stdio.h>            /* for FILE, printf(), etc. */
  37. #include <strings.h>        /* for strcpy(), etc. */
  38. #include <proto.h>            /* for function prototypes */
  39. #include "brwsr.h"            /* for various of my definitions */
  40. #include "brwsr.proto.h"    /* for my function prototypes */
  41.  
  42.  
  43. /* First, define a few external variables to hold:
  44.  *    - pointers to the document, key, pointer, and notes files;
  45.  *    - numbers indicating the current and the minimum/maximum values for:
  46.  *        INDEX item (one line for each unique word in the document);
  47.  *        CONTEXT item (one line for each occurrence of chosen INDEX word);
  48.  *        TEXT item (byte offset from start of file to current line).
  49.  *    - the actual KEY_RECs corresponding to the current INDEX item and
  50.  *        the INDEX item just before that one
  51.  *    - the subset array pointer used for proximity searching, the flag
  52.  *        empty_subset, and the count of how many current records are in
  53.  *        the working subset subset_rec_count
  54.  *    - the level of user operations:
  55.  *        0     means browsing the INDEX
  56.  *        1    means browsing the CONTEXT (key-word-in-context = KWIC)
  57.  *        2    means browsing the TEXT
  58.  *
  59.  * These items are referred to by various routines at scattered
  60.  * locations, and it seems easiest to let them reside in external
  61.  * variables....
  62.  */
  63.  
  64. FILE *doc_file = NULL, *key_file = NULL, *ptr_file = NULL,
  65.         *notes_file = NULL;
  66. long current_item[3] = {0, 0, 0};
  67. long min_item[3] = {0, 0, 0};
  68. long max_item[3] = {0, 0, 0};
  69. KEY_REC this_rec, prev_rec;
  70. char *subset = NULL;
  71. int empty_subset = TRUE;
  72. long subset_rec_count = 0;
  73. int level = INDEX;
  74.  
  75. void main()
  76.   {
  77.     char cmd[STRLEN], prevcmd[STRLEN], *gets(), *strcpy();
  78.     
  79.     prevcmd[0] = '\0';
  80.     printf ("Greetings, program! ... type '?' for help.\n");
  81.     printf ("Browser version 0.2 by ^z - 28-letter keys - 871103\n");
  82.     
  83.     while (gets (cmd))
  84.       {
  85.           do_cmd:
  86.          switch (cmd[0])
  87.           {
  88.               case '?':
  89.                   do_help ();
  90.                   break;
  91.             case '\0':
  92.                 strcpy (cmd, "+");
  93.                 /* <return> is just + */
  94.             case '+':
  95.                 /* + or - commands are both moves */
  96.             case '-':
  97.                 do_move (cmd);
  98.                 break;
  99.             case ':':
  100.                 do_open (cmd);
  101.                 break;
  102.             case '>':
  103.                 do_redirection (cmd);
  104.                 break;
  105.             case '\'':
  106.                 do_comments (cmd);
  107.                 break;
  108.             case '=':
  109.                 do_descend ();
  110.                 break;
  111.             case '^':
  112.                 do_ascend ();
  113.                 break;
  114.             case '.':
  115.                 do_multiprint (cmd);
  116.                 break;
  117.             case '*':
  118.                 do_make_subset (cmd);
  119.                 break;
  120.             case '&':
  121.                 do_add_neighborhood (cmd);
  122.                 break;
  123.             case '~':
  124.                 do_invert_subset ();
  125.                 break;
  126.             case ';':
  127.                 strcpy (cmd, prevcmd);
  128.                 goto do_cmd;
  129.                 break;
  130.             case '"':
  131.                 do_target_jump (cmd + 1);
  132.                 break;
  133.             default:
  134.                 do_target_jump (cmd);
  135.                 break;
  136.           }
  137.         strcpy (prevcmd, cmd);
  138.       }
  139.   }
  140.  
  141.